#添加任务页面类

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By

#数据
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://192.168.1.83/crm')
username = 'zhangsan'   #用户名
password = '123456'      #密码
subiect = '红红火火恍恍惚惚暴龙战士'  #添加任务中的主题内容
describe = '针不错针不错针不错针不错针不错针不错针不错adsfghjwaergtfhj针不错针不错'   #添加任务描述中的主题内容

#元素定位器
username_locator = (By.NAME,'name')      #登录账号
password_locator = (By.NAME, 'password')  #登录密码
btn_locator = (By.NAME,'submit')        #点击登录按钮

task_locator = (By.LINK_TEXT, '任务')  # 任务模块
newtask_locator = (By.LINK_TEXT, '新建任务')  # 新建任务
subiect_locator = (By.ID,'subject')    #添加任务中的主题

principal_locator = (By.ID,'owner_name') #添加任务中负责人
entirebtn_locator = (By.XPATH,'//*[@id="ta1"]/span[1]/input') #选择添加任务中第一位admin负责人
okbtn_locator = (By.XPATH,'/html/body/div[7]/div[3]/div/button[1]') #选择添加任务中选择负责人ok按钮

correlation_locator = (By.ID,'about_roles_name')   #选择任务相关人
correlation_principal_locator = (By.XPATH, '//*[@id="ta1"]/span[1]/input')  #选择添加任务相关人第一位
correlation_okbtn_locator = (By.XPATH,'/html/body/div[8]/div[3]/div/button[1]')   #任务相关人点击ok保存

belowchoice_locator = (By.XPATH,'//*[@id="select1"]')  #选择相关下拉框
belowtwochoice_locator = (By.XPATH,'//*[@id="select1"]/option[2]') #选择下拉框第二个   联系人
choice_locator = (By.ID,'module_name')  #选择相关框
onechoice_locator = (By.XPATH,'/html/body/div[9]/div[2]/table/tbody[2]/tr[1]/td[1]/input')  #选择第一个相关人
okchoice_locator = (By.XPATH,'/html/body/div[9]/div[3]/div/button[1]')          #相关点击ok

informmail_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[2]/td[4]/input[2]')  #发送通知 邮件
informletter_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[2]/td[4]/input[1]')  #发送通知 站内信

priority_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[4]/select')    #优先级框
priority_low_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[4]/select/option[3]')  #优先级低


describe_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[7]/td[2]/div/div[2]/iframe')       #描述内容
save_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')  #   添加任务中的保存按钮
entirebtnmax_locator = (By.XPATH, '//*[@id="ta1"]/input')  # 选择添加任务中全部负责人


# 操作方法
# 输入用户名
username_element = driver.find_element(*username_locator).send_keys(username)

 # 输入用户名
password_element = driver.find_element(*password_locator).send_keys(password)
sleep(2)

 # 点击登录
btn_element = driver.find_element(*btn_locator).click()
sleep(2)

#点击任务
task_element = driver.find_element(*task_locator).click()

#点击新建任务
newtask_element = driver.find_element(*newtask_locator).click()
sleep(1)

#点击主题并添加内容
subiect_element = driver.find_element(*subiect_locator).send_keys(subiect)

#点击负责人，选择，保存
principal_element = driver.find_element(*principal_locator).click()
sleep(1)
entirebtn_element = driver.find_element(*entirebtn_locator).click()  #选择全部负责人
sleep(1)
okbtn_element = driver.find_element(*okbtn_locator).click() #选择负责人后点击保存
sleep(1)

#点击相关人，选择全部负责人，保存
correlation_element = driver.find_element(*correlation_locator).click() #点击相关人
sleep(1)
correlation_principal_element = driver.find_element(*correlation_principal_locator).click()  #选择全部负责人
sleep(1)
correlation_okbtn_element = driver.find_element(*correlation_okbtn_locator).click()  #点击ok保存
sleep(1)

#选择第一个下拉框  ，第二个相关，点击并ok
belowchoice_element = driver.find_element(*belowchoice_locator).click()   #点击下拉框
sleep(1)
belowtwochoice_locator_element = driver.find_element(*belowtwochoice_locator).click()   #选择第二个 联系人
sleep(1)
choice_element = driver.find_element(*choice_locator).click()   #点击第二个输入框
sleep(1)
onchoice_element = driver.find_element(*onechoice_locator).click()   #点击第一个联系人
sleep(1)
okchoice_element = driver.find_element(*okchoice_locator).click()    #点击ok保存

#通知方式，点击站内信
informmail_element = driver.find_element(*informmail_locator).click()  #点击邮件
sleep(1)

#点击描述内容并输入内容
describe_element = driver.find_element(*describe_locator).send_keys(describe)
sleep(1)

#选择优先级  低
priority_element = driver.find_element(*priority_locator).click()
sleep(2)
priority_low_element = driver.find_element(*priority_low_locator).click()
sleep(2)


#点击保存按钮
save_element = driver.find_element(*save_locator).click()


sleep(5)
driver.quit()





